/**
 * @file tiny_queue.c
 * @brief 队列实现
 * @author 张恒宣 
 * @LastEditTime 2024/9/22
 * 
 * MIT License
 *
 * Copyright (c) 2025 张恒宣 luckkeymail@163.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/*********************
 *      头文件
 *********************/

#include "tiny_queue.h"

/*********************
*      公共函数 
*********************/

/// @brief 创建队列
/// @param block_count 块数量 
/// @param block_size 块大小
/// @return 队列实例, 如果失败返回tiny_null
tiny_queue_t tiny_queue_create(tiny_uint32_t block_count, tiny_uint32_t block_size)
{
    return tiny_queue_plus_create(block_count, block_size, tiny_queue_buf_data_copy);
}

/// @brief 释放队列
/// @param queue 待释放的队列
void tiny_queue_release(tiny_queue_t queue)
{
    if (queue)
    {
        tiny_queue_plus_release(queue);
    }
}

/// @brief 发送数据到队列
/// @param queue 待发送的队列
/// @param data 待发送的数据
/// @param size 发送数据大小, 如果大于块大小, 则直接返回
/// @param timeout 超时时间 小于于0表示无限等待
/// @return 执行状态
QUEUE_RET_STATUS tiny_queue_send(tiny_queue_t queue, tiny_uint8_t *data, tiny_uint32_t size, tiny_int32_t timeout)
{
    return tiny_queue_plus_send(queue, data, size, timeout);
}

/// @brief 接收队列数据
/// @param queue 待接收的队列
/// @param data 存储接收到的数据
/// @param size 存储数据大小, 如果大于块大小, 则直接返回
/// @param timeout 超时时间 小于于0表示无限等待
/// @return 执行状态
QUEUE_RET_STATUS tiny_queue_receive(tiny_queue_t queue, tiny_uint8_t *data, tiny_uint32_t size, tiny_int32_t timeout)
{
    return tiny_queue_plus_recv(queue, data, size, timeout);
}

/// @brief 在中断中发送队列数据
/// @param queue 待发送的队列
/// @param data 待发送的数据
/// @param size 发送数据大小, 如果大于块大小, 则直接返回
/// @param[out] is_shcduled 是否调度
/// @return 执行状态
QUEUE_RET_STATUS tiny_queue_send_irq(tiny_queue_t queue, tiny_uint8_t *data, tiny_uint32_t size, tiny_ret_status_t *is_shcduled)
{
    return tiny_queue_plus_send_irq(queue, data, size, is_shcduled);
}

/// @brief 在中断中接收队列数据
/// @param queue 待接收的队列
/// @param data 存储接收到的数据
/// @param size 存储数据大小, 如果大于块大小, 则直接返回
/// @param[out] is_shcduled 是否发送调度
/// @return 执行状态
QUEUE_RET_STATUS tiny_queue_receive_irq(tiny_queue_t queue, tiny_uint8_t *data, tiny_uint32_t size, tiny_ret_status_t *is_shcduled)
{
    return tiny_queue_plus_recv_irq(queue, data, size, is_shcduled);
}
